﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace OpenComposite.Workflow
{
	[Designer(typeof(NofMDesigner))]
	[ToolboxItem(typeof(NofMActivityToolboxItem))]
	[ToolboxBitmap(typeof(resfinder), "OpenComposite.Workflow.Resources.toolbox_nofm.png")]
	public partial class NofMActivity : ParallelActivity
	{
	}

	public class NofMDesigner : ParallelSplitDesigner
	{
		private SizeF s = SizeF.Empty;

		protected override void PaintSplit(ActivityDesignerPaintEventArgs e)
		{
			e.Graphics.DrawEllipse(outerSymbolPen, bounds);

			if ( s == SizeF.Empty )
				s = e.Graphics.MeasureString("M", TextFont);

			e.Graphics.DrawString("M",
				TextFont,
				e.DesignerTheme.ForegroundBrush,
				new PointF(WorkflowHelpers.GetCenter(bounds).X - ( s.Width / 2 ),
					WorkflowHelpers.GetCenter(bounds).Y - ( s.Height / 2 )));
		}
	}

	public class NofMActivityToolboxItem : ActivityToolboxItem
	{
		public NofMActivityToolboxItem(Type type)
			: base(type)
		{
			this.DisplayName = "N out of M";
		}
	}
}
